package com.zte.statis.control;

import com.zte.market.pojo.City;
import com.zte.market.pojo.Province;
import com.zte.market.service.CityService;
import com.zte.market.service.ProvinceService;
import com.zte.statis.pojo.*;
import com.zte.statis.service.IStatisService;
import com.zte.util.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author zeng
 * @version 1.0
 * @date 2022/10/02 星期日 17:41
 */
@Controller
@RequestMapping("/statis")
public class StatisAction {

    @Autowired
    private IStatisService statisService;

    @Autowired
    private CityService cityService;

    @Autowired
    private ProvinceService provinceService;


    /**
     * Ajax请求返回 城市数据
     * @param provinceId
     * @return
     */
    @RequestMapping("/queryCity")
    @ResponseBody
    public List<City> queryCityListByAjax(Integer provinceId){
        List<City> cities = cityService.queryCitys(provinceId);
        return cities;
    }

    /**
     * 出库统计导航
     * @param model
     * @return
     */
    @RequestMapping("/deliveryStatis")
    public String toDeliveryStatis(Condition conn,Model model,PageModel<DeliveryStatis> pageModel) {
        List<Province> provinceList = provinceService.queryProvinces();
        PageModel<DeliveryStatis> deliveryStatisList = statisService.getDeliveryStatis(conn,pageModel);
        model.addAttribute("deliveryStatisList",deliveryStatisList);
        model.addAttribute("provinceList",provinceList);
        model.addAttribute("conn",conn);
        if (conn.getProvinceId() != null ){
            List<City> cities = cityService.queryCitys(conn.getProvinceId());
            model.addAttribute("cities",cities);
        }
        return "statis/delivery/deliveryStatis";
    }

    /**
     * 厂商统计页面导航
     * @param model
     * @return
     */
    @RequestMapping("/purchaseStatis")
    public String toPurchaseStatis(Condition conn,Model model,PageModel<PurchaseStatis> pageModel) {
        List<Province> provinceList = provinceService.queryProvinces();
        PageModel<PurchaseStatis> purchaseStatisList = statisService.getPurchaseStatis(conn,pageModel);
        model.addAttribute("purchaseStatisList",purchaseStatisList);
        model.addAttribute("provinceList",provinceList);
        model.addAttribute("conn",conn);
        if (conn.getProvinceId() != null ){
            List<City> cities = cityService.queryCitys(conn.getProvinceId());
            model.addAttribute("cities",cities);
        }
        return "statis/purchase/purchaseStatis";
    }

    /**
     * 客户采购统计导航
     * @param model
     * @return
     */
    @RequestMapping("/salesStatis")
    public String toSalesStatis(Condition conn, Model model, PageModel<CustomSale> pageModel) {
        System.out.println(conn);
        List<Province> provinceList = provinceService.queryProvinces();
        PageModel<CustomSale> customSaleList = statisService.getCustomSale(conn,pageModel);
        model.addAttribute("customSaleList",customSaleList);
        model.addAttribute("provinceList",provinceList);
        model.addAttribute("conn",conn);
        if (conn.getProvinceId() != null ){
            List<City> cities = cityService.queryCitys(conn.getProvinceId());
            model.addAttribute("cities",cities);
        }
        return "statis/sales/salesStatis";
    }

    /**
     * 入库统计导航
     * @param model
     * @return
     */
    @RequestMapping("/stockStatis")
    public String toStockStatis(Condition conn,Model model,PageModel<StockStatis> pageModel) {
        List<Province> provinceList = provinceService.queryProvinces();
        PageModel<StockStatis> stockStatisList = statisService.getStockStatis(conn,pageModel);
        model.addAttribute("stockStatisList",stockStatisList);
        model.addAttribute("provinceList",provinceList);
        model.addAttribute("conn",conn);
        if (conn.getProvinceId() != null ){
            List<City> cities = cityService.queryCitys(conn.getProvinceId());
            model.addAttribute("cities",cities);
        }
        return "statis/stock/stockStatis";
    }

    /**
     * 客服订单详情
     * @param conn
     * @param pageModel
     * @param model
     * @return
     */
    @RequestMapping("/salesView")
    public String toSalesView(Condition conn,Model model,PageModel pageModel) {
        PageModel<CustomSale> salesDetailList = statisService.getSalesDetail(conn, pageModel);
        model.addAttribute("salesDetailList",salesDetailList);
        return "statis/sales/salesView";
    }

    /**
     * 厂商采购详情
     * @param conn
     * @param model
     * @param pageModel
     * @return
     */
    @RequestMapping("/purchaseView")
    public String toPurchaseView(Condition conn,Model model,PageModel pageModel) {
        PageModel<PurchaseStatis> purchaseDetailList = statisService.getPurchaseDetail(conn, pageModel);
        model.addAttribute("purchaseDetailList",purchaseDetailList);
        return "statis/purchase/purchaseView";
    }

    /**
     * 出库详情
     * @param conn
     * @param model
     * @param pageModel
     * @return
     */
    @RequestMapping("/deliveryView")
    public String toDeliveryView(Condition conn,Model model,PageModel pageModel) {
        PageModel<DeliveryStatis> deliveryDetailList = statisService.getDeliveryDetail(conn, pageModel);
        model.addAttribute("deliveryDetailList",deliveryDetailList);
        return "statis/delivery/deliveryView";
    }

    /**
     * 入库详情
     * @param conn
     * @param model
     * @param pageModel
     * @return
     */
    @RequestMapping("/stockView")
    public String toStockView(Condition conn,Model model,PageModel pageModel) {
        PageModel<StockStatis> stockDetailList = statisService.getStockDetail(conn, pageModel);
        model.addAttribute("stockDetailList",stockDetailList);
        return "statis/stock/stockView";
    }

}
